package com.sskj.gcc.ui.fragment;


import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sskj.common.rxbus2.Subscribe;
import com.sskj.common.rxbus2.ThreadMode;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.game.GameIndexBean;
import com.sskj.gcc.bean.game.GamePackgaeBean;
import com.sskj.gcc.presenter.game.GameFragmentPresenter;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.adapter.BaseAdapter;
import com.sskj.gocoin.common.adapter.ViewHolder;
import com.sskj.gocoin.m.bean.AddressList;
import com.sskj.gocoin.m.bean.AseetListBean;
import com.sskj.lib.bean.CoinBean;

import butterknife.BindView;


public class GameBottomPackageFragment extends GameBaseFragment {

    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerveiw;

    @BindView(R.id.tv_total)
    TextView tv_total;


    private BaseAdapter<GamePackgaeBean.DataBean> mAdapter;


    @Override
    public int getLayoutId() {
        return R.layout.app_fragment_game_package;
    }

    @Override
    public GameFragmentPresenter getPresenter() {
        return new GameFragmentPresenter();
    }

    @Override
    public void initView() {

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        //调整RecyclerView的排列方向
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecyclerveiw.setLayoutManager(layoutManager);
        mAdapter = new BaseAdapter<GamePackgaeBean.DataBean>(R.layout.app_item_package, null, mRecyclerveiw) {

            @Override
            public void bind(ViewHolder holder, GamePackgaeBean.DataBean item) {
                holder.getView(R.id.ll_center).setVisibility(View.GONE);
                holder.getView(R.id.tv_look).setVisibility(View.VISIBLE);
                holder.setText(R.id.tv_eat_days, item.getFeedday() + "");
                holder.setText(R.id.tv_get_food, item.getFeedoff() + "");
                holder.setText(R.id.tv_get_eggs, item.getMakeeggs() + getString(R.string.strMainActivityGame00013));
                holder.setText(R.id.tv_hungry_days, item.getHungerday() + "");

                holder.getView(R.id.tv_look).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        holder.getView(R.id.ll_center).setVisibility(View.VISIBLE);
                        holder.getView(R.id.tv_look).setVisibility(View.GONE);
                    }
                });

                holder.getView(R.id.ll_center).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        holder.getView(R.id.ll_center).setVisibility(View.GONE);
                        holder.getView(R.id.tv_look).setVisibility(View.VISIBLE);
                    }
                });
            }
        };

        mPresenter.getPeacockList();
        mPresenter.requestGameIndex();
    }

    public void onGetPeacockListSuccess(GamePackgaeBean data) {
        if (data != null) {
            mAdapter.setNewData(data.getData());
        }
    }

    public void onGameIndexSuccess(GameIndexBean gameIndexBean) {
        tv_total.setText(String.format(getString(R.string.strMainActivityGame00012), gameIndexBean.getState1(), gameIndexBean.getState7(), gameIndexBean.getState8()));
    }


}
